function UpdateShippingCost(newval){


current = document.getElementById('shippingcost').value;

//document.getElementById('shippingcost').value = (newval*1+current*1)-document.getElementById('curentshippingcost').value*1;

document.getElementById('curentshippingcost').value = newval*1;


	
}

function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) 
    elem = document.getElementById( whichLayer );
  else if( document.all ) 
      elem = document.all[whichLayer];
  else if( document.layers ) 
    elem = document.layers[whichLayer];
  vis = elem.style;

  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}



function CheckoutAlert(text, CheckoutLink){

var answer = confirm (text)
if (answer)
window.location= CheckoutLink;

}
 
function HideCheckoutBtn(whichLayer){
 
  var elem, vis;
  if( document.getElementById ) 
    elem = document.getElementById( whichLayer );
  else if( document.all ) 
      elem = document.all[whichLayer];
  else if( document.layers ) 
    elem = document.layers[whichLayer];
  vis = elem.style;

  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'none':'none';  vis.display = (vis.display==''||vis.display=='none')?'none':'none';

} 

function CheckRemaindingQty(total){

	FindQty = $("#CustomQty").text();
	if(FindQty ==""){ FindQty=1; }
	
	ThisQty = document.getElementById('QtyTotal').value; 
	Remain = FindQty*1 + ThisQty*1;
	
	document.getElementById('QtyTotal').value = Remain ;
	 
	if( (  total*1 - Remain*1  ) < 1){
	
	HideCheckoutBtn('BuyButton');
	HideCheckoutBtn('displayQtyField');
	
	}

	// UPDATE THE QTY LISTBOX
	if(total > 2){
		changeList(document.getElementById('UpdateQtyBox'),total,document.getElementById('UpdateQtyBox').value); 
	}

}

function ChangeCustomShip(val){

 document.getElementById('CustomShipping').innerHTML = val;
}

function ChangeCustomSize(val){
 
 document.getElementById('CustomSize').innerHTML = val;

}

function ChangeCustomQty(val){

  document.getElementById('CustomQty').innerHTML = val;

}

function ChangeCustomColor(val){

 document.getElementById('CustomColor').innerHTML = val;

}

function ChangeCustomExtra(val){

 document.getElementById('CustomExtra').innerHTML = val;

}

function bookmark_us(url, title){

if (window.sidebar) // firefox
    window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
    var elem = document.createElement('a');
    elem.setAttribute('href',url);
    elem.setAttribute('title',title);
    elem.setAttribute('rel','sidebar');
    elem.click();
}
else if(document.all)// ie
    window.external.AddFavorite(url, title);
}


// CHANGE QTY OF LIST BOX ON PRODUCT PAGE
function emptyList( box ) {
	// Set each option to null thus removing it
	while ( box.options.length ) box.options[0] = null;

}

// This function assigns new drop down options to the given
// drop down box from the list of lists specified

function fillList( box,total, amount  ) {

ThisQty = document.getElementById('QtyTotal').value;
NewAmount = total*1 - ThisQty*1;

	for ( i = 1; i < NewAmount+1 ; i++ ) {

		// Create a new drop down option with the
		// display text and value from arr

		option = new Option( i, i );

		// Add to the end of the existing options

		box.options[box.length] = option;
	}

	// Preselect option 0

	box.selectedIndex=0;
}

// This function performs a drop down list option change by first
// emptying the existing option list and then assigning a new set

function changeList( box, total, amount ) {

	// Next empty the slave list

	emptyList( box );

	// Then assign the new list values

	fillList( box, total, amount  );
}

 

	function generateCC(){
		var cc_number = new Array(16);
		var cc_len = 16;
		var start = 0;
		var rand_number = Math.random();

		switch(document.perform.creditCardType.value)
        {
			case "Visa":
				cc_number[start++] = 4;
				break;
			case "Discover":
				cc_number[start++] = 6;
				cc_number[start++] = 0;
				cc_number[start++] = 1;
				cc_number[start++] = 1;
				break;
			case "MasterCard":
				cc_number[start++] = 5;
				cc_number[start++] = Math.floor(Math.random() * 5) + 1;
				break;
			case "Amex":
				cc_number[start++] = 3;
				cc_number[start++] = Math.round(Math.random()) ? 7 : 4 ;
				cc_len = 15;
				break;
        }

        for (var i = start; i < (cc_len - 1); i++) {
			cc_number[i] = Math.floor(Math.random() * 10);
        }

		var sum = 0;
		for (var j = 0; j < (cc_len - 1); j++) {
			var digit = cc_number[j];
			if ((j & 1) == (cc_len & 1)) digit *= 2;
			if (digit > 9) digit -= 9;
			sum += digit;
		}

		var check_digit = new Array(0, 9, 8, 7, 6, 5, 4, 3, 2, 1);
		cc_number[cc_len - 1] = check_digit[sum % 10];

		document.perform.creditCardNumber.value = "";
		for (var k = 0; k < cc_len; k++) {
			document.perform.creditCardNumber.value += cc_number[k];
		}
	}

function Redirect2Checkout(url){

window.location = url + '?hide=1';

}